<!doctype html>
<html lang="en">
<head>
    @include('web.layout.head')
    <link rel="stylesheet" href="{{asset('/css/web/user/record.css')}}">
    <script>
        var today = '{{date('Y-m-d')}}';
        var tomorrow = '{{date('Y-m-d',strtotime('+1 day'))}}';
    </script>
    <script src="{{asset('/js/web/user/record.js')}}"></script>
</head>
<body>
@include('web.layout.header')
@include('web.layout.user_tab')
<script type="template" id="product_tpl">
    <%for(var i=0; i<@data.length; i++){ %>
    <li>
        <div class="data_delete">
            <img src="{{asset('/img/inc/icon/close2.png')}}" alt=""/>
        </div>
        <div class="data_delete2"  data-id="<%=@data[i]['history_id']%>">
            <img src="{{asset('/img/inc/icon/close3.png')}}" alt=""/>
        </div>
        <div class="imgbox">
            <a href="/product/info/<%=@data[i]['product_id']%>/<%=@data[i]['sku_id']%>" target="_blank">
                <img src="<%=@data[i]['cover_image']%>" alt=""/>
            </a>
        </div>
        <div class="price">￥<%=@data[i]['price']%></div>
        <div class="name">
            <a href="/product/info/<%=@data[i]['product_id']%>" target="_blank"><%=@data[i]['name']%></a>
        </div>
    </li>
    <% } %>
</script>

<script type="template" id="page_tpl">
<%if(@page['page_total']>1){%>
    <div class="pagination">
    <%if(@page['current_page'] > 1){%>
        <a href="{{ URL::current()}}?page=1<%= @$page['path'] ? '&'+ @page['path'] : '' %>">首页</a>
        <a href="{{ URL::current()}}?page=<%=(parseInt(@page['current_page']) - 1) + (@page['path'] ? '&'+@page['path'] : '') %>">上一页</a>
    <% } %>

    <%for (var i = 1; i <= @page['page_total']; i++) { %>
        <%
            var half_total_links = Math.floor(9 / 2);
            var from = @page['current_page'] - half_total_links;
            var to = @page['current_page'] + half_total_links;
            if (@page['current_page'] < half_total_links) {
                to += half_total_links - @page['current_page'];
            }
            if (@page['page_total'] - @page['current_page'] < half_total_links) {
                from -= half_total_links - (@page['page_total'] - @page['current_page']) - 1;
            }
        %>
        <%if(from < i && i < to) { %>
            <a <% if(@page['current_page'] == i) { %> class="active" <% } %> href="{{URL::current()}}?page=<%= i+(@page['path'] ? '&'+@page['path'] : '') %>"><%=i%></a>
        <% } %>
    <% } %>

    <%if(@page['current_page'] != @page['page_total']) { %>
        <a href="{{URL::current()}}?page=<%=(parseInt(@page['current_page']) + 1) + (@page['path'] ? '&'+ @page['path']: '') %>">下一页</a>
        <a href="{{URL::current()}}?page=<%=(@page['page_total']) + (@page['path'] ? '&' + @page['path'] : '') %>">末页</a>
    <% } %>
    <span class="follow">共<%=@page['page_total'] %>页，到第<input type="number" class="page_num" value="1" min="1" max="<%=@page['page_total'] %>">页</span>
    <a data-url="{{URL::current()}}?'<%=@page['path'] + '&page=' %>"  class="confrim-btn">确认</a>
    </div>
<% } %>
</script>

<div class="base_member_content">
    <div class="w1200">
        @include('web.layout.buyer_nav')
        <div class="nav_right flr">
            <div class="base_content">
                <div class="line_title">浏览记录</div>
                <div class="today">
                    <div class="my-subnav f-cb">
                        <div class="day fl">今天</div>
                        <div class="time fl">{{ date('Y.m.d') }}</div>
                        <div class="delete fl">
                            <a class="del-today" href="javascript:void(0);">删除</a>
                        </div>
                    </div>
                    <div class="content">
                        <div class="list">
                            <ul>
                            @if(!empty($today_data))
                                @foreach($today_data as $d)
                                <li>
                                    <div class="data_delete">
                                        <img src="{{asset('/img/inc/icon/close2.png')}}" alt=""/>
                                    </div>
                                    <div class="data_delete2"  data-id="{{$d['history_id']}}">
                                        <img src="{{asset('/img/inc/icon/close3.png')}}" alt=""/>
                                    </div>
                                    <div class="imgbox">
                                        <a href="/product/info/{{$d['product_id']}}/{{$d['sku_id']}}" target="_blank">
                                            <img src="{{$d['cover_image']}}" alt="">
                                        </a>
                                    </div>
                                    <div class="price">￥{{number_format($d['price'],2)}}</div>
                                    <div class="name">
                                        <a href="/product/info/{{$d['product_id']}}/{{$d['sku_id']}}" target="_blank">{{$d['name']}}</a>
                                    </div>
                                </li>
                                @endforeach
                            @endif
                            </ul>
                        </div>
                    </div>
                   
                </div>
                <div class="today_before">
                    <div class="my-subnav f-cb">
                        <div class="day fl">更早以前</div>
                        <div class="delete fl">
                            <a class="del-earlier" href="javascript:void(0)">删除</a>
                        </div>
                    </div>
                    <div class="content">
                        <div class="list">
                            <ul>
                            @if(!empty($earlier_data))
                                @foreach($earlier_data as $d)
                                    <li>
                                        <div class="data_delete">
                                            <img src="{{asset('/img/inc/icon/close2.png')}}" alt=""/>
                                        </div>
                                        <div class="data_delete2"  data-id="{{$d['history_id']}}">
                                            <img src="{{asset('/img/inc/icon/close3.png')}}" alt=""/>
                                        </div>
                                        <div class="imgbox">

                                            <a href="/product/info/{{$d['product_id']}}/{{$d['sku_id']}}" target="_blank">
                                                <img src="{{$d['cover_image']}}" alt="">
                                            </a>
                                        </div>
                                        <div class="price">￥{{number_format($d['price'],2)}}</div>
                                        <div class="name">
                                            <a href="/product/info/{{$d['product_id']}}/{{$d['sku_id']}}" target="_blank">{{$d['name']}}</a>
                                        </div>
                                    </li>
                                @endforeach
                            @endif
                            </ul>
                        </div>
                    </div>
                    
                </div>
            </div>
        </div>
    </div>
</div>
    <script src="{{asset('/packages/js/nodetpl.min.js')}}"></script>
<script>
$(document).ready(function(){
    //初始化模板引擎
    nodetpl.init({openTag:'<%', closeTag: '%>'});

    //加载数据
    function loadData(url, target){
        $.get(url,function(res){
            nodetpl.render($('#product_tpl').html(),res,function(products){
                $(target + ' .content .list ul').html(products);
            });
            nodetpl.render($('#page_tpl').html(),res,function(products){
                $(target + ' .page').html(products);
            });
        });
    }

    //分页点击
    $('.today').on('click','.pagination a',function(e){
        e.preventDefault();
        var url = '';
        if($(this).hasClass('confrim-btn')){
            var page = parseInt($(this).prev().find('.page_num').val());
            url  = $(this).attr('data-url') + page + '&type=today';
        }else{
            url  = $(this).attr('href') + '&type=today';
        }
        loadData(url,'.today');
        return false;
   });

   $('.today_before').on('click','.pagination a',function(e){
        e.preventDefault();
        var url = '';
        if($(this).hasClass('confrim-btn')){
            var page = parseInt($(this).prev().find('.page_num').val());
            url  = $(this).attr('data-url') + page + '&type=earlier';
        }else{
            url  = $(this).attr('href') + '&type=earlier';
        }
        loadData(url,'.today_before');
        return false;
   });

});

</script>
@include('web.layout.footer')
</body>
</html>